package com.family.web.controller.pedigree;


import com.family.common.core.controller.BaseController;
import com.family.common.core.domain.AjaxResult;
import com.family.common.core.page.TableDataInfo;
import com.family.pedigree.domain.FamilyClan;
import com.family.pedigree.domain.vo.FamilyClanQuery;
import com.family.pedigree.service.IFamilyClanService;
import lombok.RequiredArgsConstructor;
import org.aspectj.weaver.loadtime.Aj;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotBlank;

/**
 * <p>
 * 家族族谱信息
 * 前端控制器
 * </p>
 *
 * @author forever
 * @since 2024-11-10
 */
@Deprecated
@RestController
@RequestMapping("/family/clan")
@RequiredArgsConstructor
public class FamilyClanController extends BaseController {

    private final IFamilyClanService clanService;


    /**
     * 查询全部家族数
     *
     * @param clanVo 查询条件
     * @return 家族树结构
     */
    @GetMapping("/tree")
    public AjaxResult getAllTreeAndClan(FamilyClanQuery clanVo) {

        return AjaxResult.success(clanService.getAllTree(clanVo));
    }


    @Validated
    @GetMapping("/statistics")
    public AjaxResult count(@NotBlank(message = "统计类型不能为空") String type) {
        return AjaxResult.success(clanService.countByType(type));

    }

    /**
     * 查看家族列表
     *
     * @return 列表信息
     */
    @GetMapping("/list")
    public TableDataInfo list(FamilyClan clan) {
        startPage();
        return getDataTable(clanService.getList(clan));
    }


    @PostMapping
    public AjaxResult add(@RequestBody FamilyClan clan) {
        clanService.add(clan);
        return success();
    }

    @PutMapping
    public AjaxResult update(@RequestBody FamilyClan clan) {
        clanService.edit(clan);
        return success();
    }

    @DeleteMapping("/{familyId}")
    public AjaxResult delById(@PathVariable Long familyId) {
        clanService.delById(familyId);
        return success();
    }


    @GetMapping("/person-all/{nodeId}")
    public AjaxResult getPersonAll(@PathVariable Long nodeId) {
        return AjaxResult.success(clanService.getPersonAll(nodeId));
    }
}
